package com.lyhengtongwl.zqsnews.utils;

import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lyhengtongwl.zqsnews.ui.activity.*;

/**
 * Created by Steven on 2019/1/28.
 * 处理  全局跳转问题
 */
public class GlobalActionUtils {
    /**
     * actionType为全局动作，配合actionUrl一起使用；
     * 1.toURL：页面链接跳转，actionUrl传入页面链接；
     * 2.toLogin：跳转至登录画面；
     * 3.toAccount：（已登录）跳转至我的画面；
     * 4.toShare：弹出分享画面，actionUrl传入{"title" : title,"description" : description,"icon" : icon, "url" : url}；
     * 5.toGoods：跳转至商品详情页面，actionUrl传入goodsId；
     * 6.toCategory：跳转至分类画面，actionUrl传入categoryId；
     */
    public static void toPage(String actionType, Object actionUrl, FragmentActivity activity) {
        switch (actionType) {
            case "toURL"://页面链接跳转
                activity.startActivity(new Intent(activity, WebActivity.class).putExtra("url", actionUrl + ""));
                break;
            case "toLogin"://跳转登录页面
                activity.startActivity(new Intent(activity, LoginAndRegisterActivity.class));
                break;
            case "toAccount": //(已登录）跳转至我的画面
                break;
            case "toShare"://弹出分享画面，actionUrl传入{"title" : title,"description" : description,"icon" : icon, "url" : url}；
                JSONObject obj = (JSONObject) JSON.parse(actionUrl + "");
                ShowShareUtils.showShareDialog(activity, activity.getSupportFragmentManager(), obj);
                break;
            case "toGoods"://跳转至商品详情页面，actionUrl传入goodsId；
                activity.startActivity(new Intent(activity, GoodsDetailActivity.class).putExtra("goodId", actionUrl + ""));
                break;
            case "toCategory"://跳转至分类画面，actionUrl传入categoryId；
//                ((MainActivity) activity).toCategory(actionUrl.toString());
                activity.startActivity(new Intent(activity, MainActivity.class).putExtra("tab", 1).putExtra("actionUrl", actionUrl+""));
                break;
            case "toRecharge"://弹出充值页面
                if (UserUtils.checkLogin()) {
                    activity.startActivity(new Intent(activity, RechargeActivity.class).putExtra("money", actionUrl + ""));
                } else {
                    activity.startActivity(new Intent(activity, LoginAndRegisterActivity.class));
                }
                break;
        }
    }
}
